home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0574.ZIP / SDATIM.ASM < prev    next >
Assembly Source File  |  1986-11-21  |  2KB  |  132 lines

  1. include compiler.inc
  2.  
  3.     ttl    SDATIM, 1.05, 10-30-86, jk
  4.  
  5.     dseg
  6. clknam    db    'CLOCK$',0
  7. days    dw    0            ; buffer for CLOCK$
  8. minits    db    0
  9. hrs    db    0
  10. hdths    db    0
  11. secs    db    0,0
  12. months    db    31,28,31,30,31,30,31,31,30,31,30,31
  13.     cseg
  14.  
  15. ; void sdate(dest) char dest[9]; /* puts system date in DEST as string */
  16.  
  17.     procdef    sdate,<<dest, ptr>>
  18.     pushreg
  19.     call    rdclk            ; read the CLOCK$
  20.     jc    quit
  21.     mov    ax, days
  22.  
  23.     mov    dx,75            ; 1-1-80 offset
  24. gly:    add    dl,4            ; scale out leapyears
  25.     sub    ax,1461
  26.     jns    gly
  27.     add    ax,1461
  28.     cmp    ax,59            ; test for leapyear
  29.     jb    gyr            ; no adjustment needed
  30.     jne    lya            ; adjust if not leap day
  31.     inc    dl
  32.     push    dx            ; year
  33.     mov    al,29
  34.     push    ax            ; day
  35.     mov    al,2
  36.     jmp    short olyr        ; spit it out
  37. lya:    dec    ax            ; remove leap day from count
  38. gyr:    inc    dl            ; and find the year
  39.     sub    ax,365
  40.     jns    gyr
  41.     add    ax,365
  42.     push    dx            ; save year
  43.  
  44.     mov    bx,-1
  45. gmo:    inc    bx            ; find the month
  46.     mov    dl,months[bx]
  47.     sub    ax,dx
  48.     jns    gmo
  49.     add    ax,dx            ; correct day count
  50.     inc    ax            ; (CLOCK$ is zero-based)
  51.     xchg    ax,bx
  52.     push    bx            ; save day
  53.     inc    al            ; adjust month
  54.  
  55. olyr:
  56.     ldptr    di, dest        ; initialize the pointer
  57.     call    outi            ; month (initialize OUT)
  58.     mov    al, '/'
  59.     stosb
  60.     pop    ax            ; day
  61.     call    outn
  62.     mov    al, '/'
  63.     stosb
  64.     pop    ax            ; year
  65.     call    outn
  66.     xor    ax, ax
  67.     stosb
  68. quit:    pret
  69.     pend    sdate
  70.  
  71. ; void stime(dest) char dest[12]; /* puts system time in DEST as string */
  72.  
  73.     procdef    stime,<<dest1, ptr>>
  74.     pushreg
  75.     call    rdclk            ; read the CLOCK$
  76.     jc    tquit
  77.  
  78.     ldptr    di, dest1        ; initialize the pointer
  79.     mov    al, hrs            ; hours
  80.     call    outi
  81.     mov    al, ':'
  82.     stosb
  83.     mov    al, minits        ; minutes
  84.     call    outn
  85.     mov    al, ':'
  86.     stosb
  87.     mov    al, secs        ; seconds
  88.     call    outn
  89.     mov    al, '.'
  90.     stosb
  91.     mov    al, hdths        ; hundredths
  92.     call    outn
  93.     xor    ax, ax
  94.     stosb
  95. tquit:    pret
  96.     pend    stime
  97.  
  98.     internal outi            ; put 2 digits where ES:DI points
  99.     cld
  100. outn:    mov    ah,'0'
  101.     cmp    al,9
  102.     jbe    unit
  103. ten:    inc    ah            ; count tens
  104.     sub    al,10
  105.     cmp    al,9
  106.     ja    ten
  107. unit:    add    al,'0'
  108.     xchg    ah,al            ; save units
  109.     stosb                ; store tens
  110.     xchg    ah,al            ; get units back
  111.     stosb                ; store byte at ES:DI
  112.     ret
  113.     iend    outi
  114.  
  115.     internal rdclk            ; read the CLOCK$ device
  116.     mov    dx,offset clknam    ; open CLOCK$
  117.     mov    ax,3d00h
  118.     int    21h
  119.     jc    nogo
  120.     mov    bx,ax            ; read the date
  121.     mov    cx,1
  122.     mov    dx,offset days
  123.     mov    ah,3fh
  124.     int    21h
  125.     jc    nogo
  126.     mov    ah,3eh            ; release the handle
  127.     int    21h
  128. nogo:    ret
  129.     iend    rdclk
  130.  
  131.     finish
  132.